{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Dec. 2023\n",
    "## Notebook supporting Anahuac NWR Article 2\n",
    "## Plots of TWIG ICM model salinity (or stage) outputs"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Read TWIG-generated Excel products directly"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## File paths, etc read from Excel file also"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "from textwrap import wrap\n",
    "import matplotlib.dates as dates\n",
    "import time\n",
    "\n",
    "# set progress and cross checking index Trace for all input before loops\n",
    "#=0 essentially no output\n",
    "#=1 bare bones\n",
    "#=2 basic step-by-step output \n",
    "#=3 detailed (debugging)\n",
    "Trace=2\n",
    "\n",
    "## Set main file pathways"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " CHECK 1: Main directory path components \n",
      " ____________________ \n",
      "  -> Main Input directory --------------------- \n",
      "  -> C:/Ab1-NJprof-Cabinet/Manuscripts&Reviews/Anahuac-2-TWIG/ \n",
      "  -> Data branch  ----------------------------- \n",
      "  -> ConsultantDeliveries/TWIG-ICM45-47-Reruns_2021/ \n",
      "  -> Control branch --------------------------- \n",
      "  -> Analyses_NJ/PythonBased/JupCtrl/\n"
     ]
    }
   ],
   "source": [
    "# set the path names to working directories & branches\n",
    "#\n",
    "pathMain='C:/Ab1-NJprof-Cabinet/Manuscripts&Reviews\\\n",
    "/Anahuac-2-TWIG/'\n",
    "branchData='ConsultantDeliveries/TWIG-ICM45-47-Reruns_2021/'\n",
    "#sub0321P3='TWIG-ICM45-47-Reruns_0321/Phase3_rerun/'\n",
    "brnchOutAd='Analyses_NJ/PythonBased/JupOut/'\n",
    "branchControl='Analyses_NJ/PythonBased/JupCtrl/'\n",
    "if Trace>=2: print('\\n CHECK 1: Main directory path components','\\n ____________________',\n",
    "      '\\n  -> Main Input directory ---------------------',\n",
    "      '\\n  ->', pathMain,\n",
    "      '\\n  -> Data branch  -----------------------------',\n",
    "      '\\n  ->', branchData,          \n",
    "      '\\n  -> Control branch ---------------------------',\n",
    "      '\\n  ->', branchControl )          "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " input: C:/Ab1-NJprof-Cabinet/Manuscripts&Reviews/Anahuac-2-TWIG/Analyses_NJ/PythonBased/JupCtrl/NJ-MasterControl_112823.xlsx\n"
     ]
    }
   ],
   "source": [
    "## Read additional path data from the Excel file\n",
    "## NJ-MaterControl_date.xlsx\"\n",
    "\n",
    "# Read the control paramenters into data frame Control\n",
    "# tab='tabsSal'\n",
    "pathControl=pathMain+branchControl\n",
    "fileControl='NJ-MasterControl_112823.xlsx'\n",
    "path2file=pathControl+fileControl\n",
    "if Trace>=2: print('\\n input:',path2file)\n",
    "\n",
    "# set the column names\n",
    "colnameCtrl=['RunNo','ScLbl1','Phase','TWIG','type',\n",
    "'tabname','Benifits','AltLabel','Manu','Comments']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "           RunNo\n",
      "count  21.000000\n",
      "mean   11.000000\n",
      "std     6.204837\n",
      "min     1.000000\n",
      "25%     6.000000\n",
      "50%    11.000000\n",
      "75%    16.000000\n",
      "max    21.000000\n",
      "\n",
      " number of TWIG runs in control data file= 21\n",
      "\n",
      "  first few rows of control data file\n",
      "   RunNo    ScLbl1 Phase  TWIG type                  tabname         Benifits  \\\n",
      "0      1  PI-01sal     I  G001  sal         DryBaseline_G001      Actual (Pi)   \n",
      "1      2  PI-02sal     I  G002  sal   3000ac-ft_100days_G002   Fxd-3k100d0701   \n",
      "2      3  PI-03sal     I  G003  sal   6000ac-ft_100days_G003   Fxd-6k100d0701   \n",
      "3      4  PI-04sal     I  G004  sal  10000ac-ft_100days_G004  Fxd-10k100d0701   \n",
      "\n",
      "           AltLabel              Manu Comments  \n",
      "0  Baseline* (2011)  Baseline* (2011)  no comm  \n",
      "1            not in            not in  no comm  \n",
      "2    G003-MethodFig    G003-MethodFig  no comm  \n",
      "3    G004-MethodFig    G004-MethodFig  no comm  \n"
     ]
    }
   ],
   "source": [
    "DFC = pd.read_excel(path2file,sheet_name='tabsSal',skiprows=5,names=colnameCtrl,nrows=21)\n",
    "if Trace>=2: print(DFC.describe())\n",
    "noRuns=len(DFC.index)\n",
    "if Trace>=2: print('\\n number of TWIG runs in control data file=',noRuns)\n",
    "if Trace>=2: print('\\n  first few rows of control data file')\n",
    "if Trace>=2: print(DFC[:4])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## In same Excel file, retrieve complete path building components\n",
    "## from tab 'PhasePathSal'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "       PhaseMatch                   pathPhase  \\\n",
      "count           3                           3   \n",
      "unique          3                           3   \n",
      "top             I  TWIG-ICM45-47-Reruns_0521\\   \n",
      "freq            1                           1   \n",
      "\n",
      "                                            file  \n",
      "count                                          3  \n",
      "unique                                         3  \n",
      "top     tnc_anwr_scenario_salinity_05062021.xlsx  \n",
      "freq                                           1  \n",
      "\n",
      " number of Phase-path-file inputs= 3\n",
      "\n",
      "  first few rows of control data file\n",
      "  PhaseMatch                                pathPhase  \\\n",
      "0          I               TWIG-ICM45-47-Reruns_0521\\   \n",
      "1         II  TWIG-ICM45-47-Reruns_0321\\Phase2_rerun\\   \n",
      "2        III  TWIG-ICM45-47-Reruns_0321\\Phase3_rerun\\   \n",
      "\n",
      "                                               file  \n",
      "0          tnc_anwr_scenario_salinity_05062021.xlsx  \n",
      "1  nwf_anwr_icm_model_output_salinity_03172021.xlsx  \n",
      "2               nwf_anwr_icm_salinity_03172021.xlsx  \n"
     ]
    }
   ],
   "source": [
    "# set the column names\n",
    "colnamePath=['PhaseMatch','pathPhase','file']\n",
    "DFP = pd.read_excel(path2file,sheet_name='PhasepathSal',skiprows=6,names=colnamePath,nrows=3)\n",
    "if Trace>=2: print(DFP.describe())\n",
    "noPpf=len(DFP.index)\n",
    "if Trace>=2: print('\\n number of Phase-path-file inputs=',noPpf)\n",
    "if Trace>=2: print('\\n  first few rows of control data file')\n",
    "if Trace>=2: print(DFP[:3])   \n",
    "\n",
    "# reset Df index to the RunNo column\n",
    "#DFC.set_index('RunNo')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## User Control Option\n",
    "## Use Keyboard input of fix\n",
    "## the desired scenarios to analyze"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## these are the Column A values on tabsSal in NJ-MasterControl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# RunA=input(\"Enter Run A as integer :\\n\")\n",
    "# RunB=input(\"Enter Run B as integer :\\n\")\n",
    "#>>> this set for 'Initial runs' set of figures [Figure 7 @01/24]\n",
    "RunA=1\n",
    "RunB=5\n",
    "RunC=6\n",
    "RunD=7\n",
    "#>>> Final set of figures from the -X3 notebook"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Indexes for Run A / B:  0  /  4\n",
      "<class 'int'>\n",
      "\n",
      " Paramenters for the runs to analyze \n",
      " ________________________________________________________________________ \n",
      " =====   RunA / Phase / ScLbl1    / tabname  / ArticleNo \n",
      " =====     1  / I     / PI-01sal / DryBaseline_G001 / Baseline* (2011) \n",
      " =====   RunB / Phase / Label    / tabname \n",
      " =====     5  / I     / PI-05sal / 3000ac-ft_50days_G005 / Preset_3k_50* \n",
      " =====   RunC / Phase / ScLbl1    / tabname  / ArticleNo \n",
      " =====     6  / I     / PI-06sal / 6000ac-ft_50days_G006 / Preset_6k_50* \n",
      " =====   RunD / Phase / ScLbl1    / tabname  / ArticleNo \n",
      " =====     7  / I     / PI-07sal / 10000ac-ft_50days_G007 / Preset_10k_50*\n"
     ]
    }
   ],
   "source": [
    "Aindx=int(RunA)-1\n",
    "Bindx=int(RunB)-1\n",
    "Cindx=int(RunC)-1\n",
    "Dindx=int(RunD)-1\n",
    "if Trace>=2: print('\\n Indexes for Run A / B: ',Aindx,' / ',Bindx)\n",
    "\n",
    "print(type(RunA))\n",
    "\n",
    "## Based on entered values \n",
    "## set additional input / output file path and name parameters\n",
    "\n",
    "# retrive the Scenario Label, Phase, etc settings for the runs\n",
    "# colnameCtrl=['RunNo','ScLbl1','Phase','TWIG','type',\n",
    "# 'tabname','Benifits','AltLabel','Manu','Comments']\n",
    "\n",
    "#Phases=DFC['Phase']\n",
    "#PhScn2=Phase[Sc2]\n",
    "PhRunA=DFC.at[Aindx,'Phase']\n",
    "LblRunA=DFC.at[Aindx,'ScLbl1']\n",
    "TbRunA=DFC.at[Aindx,'tabname']\n",
    "ArtLblA=DFC.at[Aindx,'Manu']\n",
    "\n",
    "PhRunB=DFC.at[Bindx,'Phase']\n",
    "LblRunB=DFC.at[Bindx,'ScLbl1']\n",
    "TbRunB=DFC.at[Bindx,'tabname']\n",
    "ArtLblB=DFC.at[Bindx,'Manu']\n",
    "\n",
    "PhRunC=DFC.at[Cindx,'Phase']\n",
    "LblRunC=DFC.at[Cindx,'ScLbl1']\n",
    "TbRunC=DFC.at[Cindx,'tabname']\n",
    "ArtLblC=DFC.at[Cindx,'Manu']\n",
    "\n",
    "PhRunD=DFC.at[Dindx,'Phase']\n",
    "LblRunD=DFC.at[Dindx,'ScLbl1']\n",
    "TbRunD=DFC.at[Dindx,'tabname']\n",
    "ArtLblD=DFC.at[Dindx,'Manu']\n",
    "if Trace>=2: print('\\n Paramenters for the runs to analyze',\n",
    "            '\\n ________________________________________________________________________',       \n",
    "            '\\n =====   RunA / Phase / ScLbl1    / tabname  / ArticleNo',\n",
    "            '\\n =====    ',RunA,' /', PhRunA,'    /', LblRunA,'/', TbRunA,'/', ArtLblA,\n",
    "            '\\n =====   RunB / Phase / Label    / tabname',\n",
    "            '\\n =====    ',RunB,' /', PhRunB,'    /', LblRunB,'/', TbRunB,'/', ArtLblB,\n",
    "            '\\n =====   RunC / Phase / ScLbl1    / tabname  / ArticleNo',\n",
    "            '\\n =====    ',RunC,' /', PhRunC,'    /', LblRunC,'/', TbRunC,'/', ArtLblC,\n",
    "            '\\n =====   RunD / Phase / ScLbl1    / tabname  / ArticleNo',\n",
    "            '\\n =====    ',RunD,' /', PhRunD,'    /', LblRunD,'/', TbRunD,'/', ArtLblD)                   "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Set plot Labeling variables"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "   Lchoice= 3\n",
      "\n",
      " Lchoice was-  3\n",
      "\n",
      "   Labels: Baseline* (2011) // Preset_3k_50* // Preset_6k_50* // Preset_10k_50*\n"
     ]
    }
   ],
   "source": [
    "#Key board input the label convention for scenarios\n",
    "#Lchoice=input(\"Enter Label Control [1=Sclbl1; 2=tabname; 3=Manu]:\\n\")\n",
    "Lchoice=3\n",
    "\n",
    "#Lchoice.type()\n",
    "\n",
    "print('\\n   Lchoice=', Lchoice)  \n",
    "Trace=2\n",
    "\n",
    "#print('\\n   LblRunA', LblRunA)  \n",
    "\n",
    "if Lchoice==1:\n",
    "    Y1label=LblRunA\n",
    "    Y2label=LblRunB\n",
    "    Y3label=LblRunC\n",
    "    Y4label=LblRunD\n",
    "    print('\\n Lchoice was-',Lchoice)\n",
    "elif Lchoice==2:\n",
    "    Y1label=TbRunA\n",
    "    Y2label=TbRunB\n",
    "    Y3label=TbRunC\n",
    "    Y4label=TbRunD\n",
    "    print('\\n Lchoice was-',Lchoice)\n",
    "else:\n",
    "    print('\\n Lchoice was- ',Lchoice)\n",
    "    Y1label=ArtLblA\n",
    "    Y2label=ArtLblB\n",
    "    Y3label=ArtLblC\n",
    "    Y4label=ArtLblD    \n",
    "        \n",
    "if Trace>=1: print('\\n   Labels:',Y1label, \"//\", Y2label, \"//\", Y3label, \"//\", Y4label)  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Given the scenarios desired - Contruct complete file path(s) and tabs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Paramenters for the runs to Plot and/or Analyze \n",
      " ________________________________________________________________________ \n",
      " ==RunA / Phase / Label    / tabname \n",
      " -> 1  / I     / PI-01sal / DryBaseline_G001 \n",
      " -> C:/Ab1-NJprof-Cabinet/Manuscripts&Reviews/Anahuac-2-TWIG/ConsultantDeliveries/TWIG-ICM45-47-Reruns_2021/TWIG-ICM45-47-Reruns_0521\\tnc_anwr_scenario_salinity_05062021.xlsx \n",
      " ==RunB / Phase / Label    / tabname \n",
      " -> 5  / I     / PI-05sal / 3000ac-ft_50days_G005 \n",
      " -> C:/Ab1-NJprof-Cabinet/Manuscripts&Reviews/Anahuac-2-TWIG/ConsultantDeliveries/TWIG-ICM45-47-Reruns_2021/TWIG-ICM45-47-Reruns_0521\\tnc_anwr_scenario_salinity_05062021.xlsx\n",
      "\n",
      " Paramenters for the runs to Plot and/or Analyze \n",
      " ________________________________________________________________________ \n",
      " ==RunC / Phase / Label    / tabname \n",
      " -> 6  / I     / PI-06sal / 6000ac-ft_50days_G006 \n",
      " -> C:/Ab1-NJprof-Cabinet/Manuscripts&Reviews/Anahuac-2-TWIG/ConsultantDeliveries/TWIG-ICM45-47-Reruns_2021/TWIG-ICM45-47-Reruns_0521\\tnc_anwr_scenario_salinity_05062021.xlsx \n",
      " ==RunD / Phase / Label    / tabname \n",
      " -> 7  / I     / PI-07sal / 10000ac-ft_50days_G007 \n",
      " -> C:/Ab1-NJprof-Cabinet/Manuscripts&Reviews/Anahuac-2-TWIG/ConsultantDeliveries/TWIG-ICM45-47-Reruns_2021/TWIG-ICM45-47-Reruns_0521\\tnc_anwr_scenario_salinity_05062021.xlsx\n"
     ]
    }
   ],
   "source": [
    "#if Trace>=2: print(DFP)\n",
    "\n",
    "#df.loc[df['Fee'] == 22000, 'Courses'].iloc[0]\n",
    "DataPathA=DFP.loc[DFP['PhaseMatch']==PhRunA, 'pathPhase'].iloc[0]\n",
    "DataFileA=DFP.loc[DFP['PhaseMatch']==PhRunA, 'file'].iloc[0]\n",
    "\n",
    "DataPathB=DFP.loc[DFP['PhaseMatch']==PhRunB, 'pathPhase'].iloc[0]\n",
    "DataFileB=DFP.loc[DFP['PhaseMatch']==PhRunB, 'file'].iloc[0]\n",
    "\n",
    "DataPathC=DFP.loc[DFP['PhaseMatch']==PhRunC, 'pathPhase'].iloc[0]\n",
    "DataFileC=DFP.loc[DFP['PhaseMatch']==PhRunC, 'file'].iloc[0]\n",
    "\n",
    "DataPathD=DFP.loc[DFP['PhaseMatch']==PhRunD, 'pathPhase'].iloc[0]\n",
    "DataFileD=DFP.loc[DFP['PhaseMatch']==PhRunD, 'file'].iloc[0]\n",
    "\n",
    "if Trace>2: print('\\n Paramenters for the runs to Plot and/or Analyze',\n",
    "            '\\n ________________________________________________________________________',       \n",
    "            '\\n ==RunA / Phase / Label    / tabname',\n",
    "            '\\n ->',RunA,' /', PhRunA,'    /', LblRunA,'/', TbRunA,\n",
    "            '\\n ->',DataPathA,DataFileA,\n",
    "            '\\n ==RunD / Phase / Label    / tabname',\n",
    "            '\\n ->',RunD,' /', PhRunD,'    /', LblRunD,'/', TbRunD,\n",
    "            '\\n ->',DataPathD,DataFileD)\n",
    "\n",
    "#Remove leading blank from each \"Data\" text string\n",
    "DataPathA=DataPathA.rstrip('\\n')\n",
    "DataFileA=DataFileA.rstrip('\\n')\n",
    "# set total file input paths\n",
    "TotPathA=pathMain+branchData+DataPathA+DataFileA\n",
    "TotPathB=pathMain+branchData+DataPathB+DataFileB\n",
    "TotPathC=pathMain+branchData+DataPathC+DataFileC\n",
    "TotPathD=pathMain+branchData+DataPathD+DataFileD\n",
    "\n",
    "if Trace>=1: print('\\n Paramenters for the runs to Plot and/or Analyze',\n",
    "            '\\n ________________________________________________________________________',       \n",
    "            '\\n ==RunA / Phase / Label    / tabname',\n",
    "            '\\n ->',RunA,' /', PhRunA,'    /', LblRunA,'/', TbRunA,\n",
    "            '\\n ->',TotPathA,\n",
    "            '\\n ==RunB / Phase / Label    / tabname',\n",
    "            '\\n ->',RunB,' /', PhRunB,'    /', LblRunB,'/', TbRunB,\n",
    "            '\\n ->',TotPathB)\n",
    "if Trace>=1: print('\\n Paramenters for the runs to Plot and/or Analyze',\n",
    "            '\\n ________________________________________________________________________',       \n",
    "            '\\n ==RunC / Phase / Label    / tabname',\n",
    "            '\\n ->',RunC,' /', PhRunC,'    /', LblRunC,'/', TbRunC,\n",
    "            '\\n ->',TotPathC,\n",
    "            '\\n ==RunD / Phase / Label    / tabname',\n",
    "            '\\n ->',RunD,' /', PhRunD,'    /', LblRunD,'/', TbRunD,\n",
    "            '\\n ->',TotPathD)    "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## With Constructed paths, input data from files"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Time Series of salinity or stage data by ICM cell \n",
    "# set the column names\n",
    "colnames=['date','Cell 01','Cell 02','Cell 03','Cell 04',\n",
    "'Cell 05','Cell 06','Cell 07','Cell 08','Cell 09','Cell 10',\n",
    "'Cell 11','Cell 12','Cell 13','Cell 14','Cell 15',\n",
    "'Cell 16','Cell 17','Cell 18','Cell 19','Cell 20',\n",
    "'Cell 21','Cell 22','Cell 23','Cell 24','Cell 25',\n",
    "'Cell 26','Cell 27','Cell 28','Cell 29','Cell 30',\n",
    "'Cell 31','Cell 32','Cell 33','Cell 34','Cell 35',\n",
    "'Cell 36','Cell 37','Cell 38','Cell 39','Cell 40',\n",
    "'Cell 41','Cell 42','Cell 43','Cell 44','Cell 45',\n",
    "'Cell 46','Cell 47','Cell 48','Cell 49','Cell 50',\n",
    "'Cell 51','Cell 52','Cell 53','Cell 54','Cell 55',\n",
    "'Cell 56','Cell 57','Cell 58','Cell 59','Cell 60',\n",
    "'Cell 61','Cell 62','Cell 63','Cell 64','Cell 65','Cell 66']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Read input for Scenario1 on Tab1\n",
    "print('\\n Hold on - Reading 1st file')\n",
    "RunAdata = pd.read_excel(TotPathA,sheet_name=TbRunA,skiprows=0,names=colnames,nrows=1000)\n",
    "#if Trace>=2: print(RunAdata.describe())\n",
    "noDaysInA=len(RunAdata.index)\n",
    "if Trace>=2: print('\\n number of total days in input data file=',noDaysInA)\n",
    "if Trace>=2: print('\\n ',TbRunA,' [RunA] first few rows of data file')\n",
    "if Trace>=2: print(RunAdata[75:80])\n",
    "#\n",
    "print('\\n Hold on - Reading 2nd file')\n",
    "RunBdata = pd.read_excel(TotPathB,sheet_name=TbRunB,skiprows=0,names=colnames,nrows=1000)\n",
    "#\n",
    "print('\\n Hold on - Reading 3Rd file')\n",
    "RunCdata = pd.read_excel(TotPathC,sheet_name=TbRunC,skiprows=0,names=colnames,nrows=1000)\n",
    "#\n",
    "print('\\n Hold on - Reading 4TH file')\n",
    "RunDdata = pd.read_excel(TotPathD,sheet_name=TbRunD,skiprows=0,names=colnames,nrows=1000)\n",
    "#if Trace>=2: print(RunBdata.describe())\n",
    "noDaysInD=len(RunDdata.index)\n",
    "if Trace>=2: print('\\n number of total days in input data file=',noDaysInD)\n",
    "if Trace>=2: print('\\n ',TbRunD,' [RunD] first few rows of data file')\n",
    "if Trace>=2: print(RunDdata[75:80])\n",
    "\n",
    "## prep with 'to_datetime' \n",
    "# this operation converts to datetime and overwrites the variable 'date' in the df\n",
    "RunAdata['date']=pd.to_datetime(RunAdata['date'], format='%m/%d/%Y')\n",
    "RunBdata['date']=pd.to_datetime(RunBdata['date'], format='%m/%d/%Y')\n",
    "RunCdata['date']=pd.to_datetime(RunCdata['date'], format='%m/%d/%Y')\n",
    "RunDdata['date']=pd.to_datetime(RunDdata['date'], format='%m/%d/%Y')\n",
    "if Trace>2:\n",
    "    RunAdata.info()\n",
    "    RunBdata.info()\n",
    "    RunCdata.info()\n",
    "    RunDdata.info()\n",
    "\n",
    "print('\\n Finished with Scenario data input and date time conversion')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "## From Control file 'SalPlotCtrl-Time'- input Begin and End time for plots and analyses\n",
    "\n",
    "fnameCA='ManuSalPlotCtrl-TimeTitles'+'.txt'\n",
    "# Cross check file name build result\n",
    "if Trace>=2: print('\\n Control time data file name=',fnameCA)\n",
    "pathCA=pathMain+branchControl+fnameCA\n",
    "\n",
    "CtrlA=open(pathCA,'r')\n",
    "skipA1=6\n",
    "for sk in range(skipA1):\n",
    "    Nuttin=CtrlA.readline()\n",
    "#\n",
    "MainTitle=CtrlA.readline()\n",
    "MainTitle=MainTitle.rstrip('\\n')\n",
    "skipA2=2\n",
    "for sk2 in range(skipA2):\n",
    "    Nuttin=CtrlA.readline()\n",
    "#\n",
    "SecondTitle=CtrlA.readline()\n",
    "SecondTitle=SecondTitle.rstrip('\\n')\n",
    "if Trace>0: print('_________________Titles:______________________','\\n Main: ',MainTitle,\\\n",
    "                  '\\n  2nd:', SecondTitle)  \n",
    "skipA2=2\n",
    "for sk in range(skipA2):\n",
    "    Nuttin=CtrlA.readline()    \n",
    "Start=CtrlA.readline()\n",
    "Start=Start.rstrip('\\n')\n",
    "Stop= CtrlA.readline()\n",
    "Stop=Stop.rstrip('\\n')\n",
    "if Trace>0: print(\"        >>>>>> Control A: Times <<<<<<<\",\n",
    "                 \"\\n _______________________________________________\",\n",
    "                 \"\\n  Start time =\", Start,\" Stop time  =\", Stop)                 \n",
    "CtrlA.close\n",
    "\n",
    "## Based on desired time window (Control A input), \n",
    "## set time-related parameters\n",
    "\n",
    "# find offset to beginning of time window of interest as in Control A\n",
    "# variables \"Start\" & \"Stop\" input above\n",
    "ICMSimStart='01/01/2010'\n",
    "ICMSimStart\n",
    "\n",
    "#start_time=pd.to_datetime('10-01-1921')\n",
    "#end_time=pd.to_datetime('09-30-1922')\n",
    "ICMstart_time=pd.to_datetime(ICMSimStart)\n",
    "start_time=pd.to_datetime(Start)\n",
    "end_time=pd.to_datetime(Stop)\n",
    "delstart=start_time-ICMstart_time\n",
    "duration=end_time-start_time\n",
    "offset=delstart.days\n",
    "nodays=duration.days+1\n",
    "if Trace>=1: print('\\n              Time Control Parameters',\n",
    "            '\\n ________________________________________________________________________',       \n",
    "            '\\n =====         ICMSim data file start [ICMstart_time]: ',ICMstart_time,\n",
    "            '\\n =====    Subset Time Series to start at [start_time]: ',start_time,\n",
    "            '\\n =====         Subset Time Series to end at[end_time]: ',end_time,\n",
    "            '\\n =====      Duration of Subset time series   [nodays]: ',nodays,\n",
    "            '\\n =====              Offset from begin ICMSim [offset]: ',offset)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Extract the specified time segment from the overall time series"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# TSubA and B will still be large 2-D arrays [date x cell], but\n",
    "# subsetted to jsut time of interest\n",
    "TSubA=RunAdata[(RunAdata.date <= end_time) & (RunAdata.date >= start_time)]\n",
    "#\n",
    "TSubB=RunBdata[(RunBdata.date <= end_time) & (RunBdata.date >= start_time)]\n",
    "#\n",
    "TSubC=RunCdata[(RunCdata.date <= end_time) & (RunCdata.date >= start_time)]\n",
    "#\n",
    "TSubD=RunDdata[(RunDdata.date <= end_time) & (RunDdata.date >= start_time)]\n",
    "\n",
    "\n",
    "#verify extracted window of time series TSubA\n",
    "# \n",
    "if Trace>=2: print('\\n In extracted subset of RunC, subset data:',\n",
    "           '\\n',TSubC[180:188])\n",
    "if Trace>=2: print('\\n in extracted subset of RunC, subset data:',\n",
    "           '\\n',TSubC[280:288])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## JUST A TEST - NOT KEPT IN PRESENTED RESULTS\n",
    "## due to difference in model across Phases, the several 10k_50day data have\n",
    "## differences among versions\n",
    "## for plotting consistency, splice in the pre July1 values from baseline\n",
    "## into the time series for this scenario [the RunDdata leading to TSubD]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# # set the splice time\n",
    "# splice_time=pd.to_datetime('2011-06-30')\n",
    "\n",
    "# # create new time series, 2 parts\n",
    "# TSubDprm1=RunAdata[(RunAdata.date <= splice_time)& (RunAdata.date >= start_time)]\n",
    "\n",
    "# #verify spliced time series TSubDprime\n",
    "# # \n",
    "# if Trace>=2: print('\\n TsubDprime, before splice:',\n",
    "#            '\\n',TSubDprm1[176:])\n",
    "\n",
    "# # overwrite up to the splice\n",
    "# TSubDprm2=RunDdata[(RunDdata.date > splice_time)& (RunDdata.date <= end_time)]\n",
    "# if Trace>=2: print('\\n after spliced data:',\n",
    "#            '\\n',TSubDprm2[:8])\n",
    "\n",
    "# # combine the subparts\n",
    "# TSubDprime=pd.concat([TSubDprm1,TSubDprm2])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## End data input, and temporal subsetting\n",
    "## develop plot(s) "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PLOT 1 - single figure mubltiple cells"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# set the plot X-axis to dates\n",
    "Dateplot=TSubA['date']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# rigorous plot axis control\n",
    "dp1='2011-01-01'\n",
    "dp2='2011-12-31'\n",
    "#\n",
    "dpstart=pd.to_datetime(dp1)\n",
    "dpstop=pd.to_datetime(dp2)\n",
    "#\n",
    "dpCelltext=pd.to_datetime('2011-12-08')\n",
    "dpMDtext1=pd.to_datetime('2011-01-15')\n",
    "dpztJan=pd.to_datetime('2011-01-05')\n",
    "dpztFeb=pd.to_datetime('2011-02-05')\n",
    "dpztMar=pd.to_datetime('2011-03-05')\n",
    "dpztApr=pd.to_datetime('2011-04-05')\n",
    "dpztApr2=pd.to_datetime('2011-04-15')\n",
    "dpztMay=pd.to_datetime('2011-05-05')\n",
    "dpztOct=pd.to_datetime('2011-10-05')\n",
    "dpztOct2=pd.to_datetime('2011-10-10')\n",
    "if Trace>=2: print('\\n Set time locations for text boxes:',\n",
    "           '\\n Example, dpMDtext1 =', dpMDtext1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# THIS IS FOR FIGURE ON EARLY ICM RESULTS\n",
    "Celllist=['Cell 20']\n",
    "#Celllist=['Cell 11','Cell 17','Cell 26']\n",
    "# set overall figure\n",
    "#fig, axB = plt.subplots(nrows=1,ncols=1,figsize=(10, 3.6))\n",
    "for Cell in Celllist:\n",
    "#    BuildTtl='JD Transition zone: '+Cell\n",
    "    ybase=TSubA[Cell]\n",
    "    yres1=TSubB[Cell]\n",
    "    yres2=TSubC[Cell]\n",
    "    yres3=TSubD[Cell]\n",
    "#    yres3=TSubDprime[Cell]\n",
    "#Option A - for the defined portion of time series\n",
    "# Plot the suite of cell results\n",
    "    fig, axB = plt.subplots(nrows=1,ncols=1,figsize=(10, 3.6))\n",
    "# baseline    \n",
    "    axB.plot_date(Dateplot,ybase,'k',linewidth=2,linestyle='-',label=Y1label)\n",
    "# 1st result\n",
    "    axB.plot_date(Dateplot,yres1,'blue',linewidth=2,linestyle=':',label=Y2label)\n",
    "# 2nd result\n",
    "    axB.plot_date(Dateplot,yres2,'blue',linewidth=2,linestyle='--',label=Y3label)\n",
    "# 3rd result\n",
    "    axB.plot_date(Dateplot,yres3,'blue',linewidth=2,linestyle='-',label=Y4label)\n",
    "# set plot labels, etc\n",
    "#    axB.set_xlabel('Date',labelpad=10,fontsize=20)\n",
    "    axB.set_xlim([dpstart, dpstop])\n",
    "    axB.set_ylabel('Salinity (ppt)',labelpad=10,fontsize=16)\n",
    "    axB.set_ylim(bottom=0,top=25)\n",
    "#    axB.set_title(BuildTtl)\n",
    "# add horizontal lines at target salinities\n",
    "# Freshwater zone: 0-3\n",
    "#     axB.axhline(0,color='green')\n",
    "#     axB.axhline(3,color='green')\n",
    "#     plt.text(dpztOct, 0.5, 'fresh veg. zone, lower target', color='k',fontsize = 9, fontstyle='italic') \n",
    "#     plt.text(dpztOct, 3.5, 'fresh veg. zone, upper target', color='k',fontsize = 9, fontstyle='italic') \n",
    "# Transition zone: 2 -6\n",
    "    axB.axhline(2,color='green')\n",
    "    axB.axhline(6,color='green')\n",
    "    plt.text(dpztApr, 2.5, 'Transition zone, lower target', color='k',fontsize = 9, fontstyle='italic') \n",
    "    plt.text(dpztApr, 6.5, 'Transition zone, upper target', color='k',fontsize = 9, fontstyle='italic') \n",
    "# S patens zone: 6 - 12\n",
    "#     axB.axhline(6,color='green')\n",
    "#     axB.axhline(12,color='green')\n",
    "#     plt.text(dpztOct, 6.5, 'S.patens zone, lower target', color='k',fontsize = 9, fontstyle='italic') \n",
    "#     plt.text(dpztOct, 12.5, 'S. patens zone, upper target', color='k',fontsize = 9, fontstyle='italic') \n",
    "# add Mottled Duck target    \n",
    "    axB.axhline(9,color='lime')\n",
    "  #  plt.text(dpMDtext1, 7.9, 'Mottled Duck, upper target', color='k',fontsize = 9, fontstyle='italic')\n",
    "    plt.text(dpztApr, 9.5, 'Mottled Duck, upper target', color='k',fontsize = 9, fontstyle='italic')   \n",
    "#\n",
    "    axB.xaxis.grid(True, which=\"major\")\n",
    "#axB.yaxis.grid()\n",
    "    axB.xaxis.set_major_locator(dates.MonthLocator())\n",
    "    axB.xaxis.set_major_formatter(dates.DateFormatter('%b\\n%Y'))\n",
    "    axB.legend(loc='upper left')\n",
    "#Adding text inside a rectangular box by using the keyword 'bbox' \n",
    "    plt.text(dpCelltext, 23, Cell, fontsize = 10)  \n",
    "    plt.tight_layout()     \n",
    "#plt.show()\n",
    "#Save output figure\n",
    "#    OutfileRoot='HandlingVersions_Base-X-3-50day-10kspliced'+Cell\n",
    "#    OutfileRoot='HandlingVersions_Base-X-3-50day-Origs'+Cell\n",
    "#     OutfileRoot='Fig8_Base-X3_50day'+Cell\n",
    "#     PathOutFile=pathMain+brnchOutAd+OutfileRoot\n",
    "#     plt.savefig(PathOutFile)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# THIS IS FOR NEXT FIGURE ON FINAL PHASE ICM RESULTS\n",
    "Celllist=['Cell 17']\n",
    "#Celllist=['Cell 11','Cell 17','Cell 26']\n",
    "# set overall figure\n",
    "#fig, axB = plt.subplots(nrows=1,ncols=1,figsize=(10, 3.6))\n",
    "for Cell in Celllist:\n",
    "#    BuildTtl='JD Transition zone: '+Cell\n",
    "    ybase=TSubA[Cell]\n",
    "    yres1=TSubB[Cell]\n",
    "    yres2=TSubC[Cell]\n",
    "    yres3=TSubD[Cell]\n",
    "#    yres3=TSubDprime[Cell]\n",
    "#Option A - for the defined portion of time series\n",
    "# Plot the suite of cell results\n",
    "    fig, axB = plt.subplots(nrows=1,ncols=1,figsize=(10, 3.6))\n",
    "# baseline    \n",
    "    axB.plot_date(Dateplot,ybase,'k',linewidth=2,linestyle='-',label=Y1label)\n",
    "# 1st result [SAME scenario as yres3 in first plots above]\n",
    "    axB.plot_date(Dateplot,yres1,'blue',linewidth=2,linestyle='-',label=Y2label)\n",
    "# 2nd result\n",
    "    axB.plot_date(Dateplot,yres2,'dodgerblue',linewidth=2,linestyle='--',label=Y3label)\n",
    "# 3rd result\n",
    "    axB.plot_date(Dateplot,yres3,'slategrey',linewidth=2,linestyle='-',label=Y4label)\n",
    "# set plot labels, etc\n",
    "#    axB.set_xlabel('Date',labelpad=10,fontsize=20)\n",
    "    axB.set_xlim([dpstart, dpstop])\n",
    "    axB.set_ylabel('Salinity (ppt)',labelpad=10,fontsize=16)\n",
    "    axB.set_ylim(bottom=0,top=25)\n",
    "#    axB.set_title(BuildTtl)\n",
    "# add horizontal lines at target salinities\n",
    "# Freshwater zone: 0-3\n",
    "#     axB.axhline(0,color='green')\n",
    "#     axB.axhline(3,color='green')\n",
    "#     plt.text(dpztOct2, 0.5, 'fresh veg. zone, lower target', color='k',fontsize = 9, fontstyle='italic') \n",
    "#     plt.text(dpztApr2, 3.5, 'fresh veg. zone, upper target', color='k',fontsize = 9, fontstyle='italic') \n",
    "# Transition zone: 2 -6\n",
    "    axB.axhline(2,color='green')\n",
    "    axB.axhline(6,color='green')\n",
    "    plt.text(dpztOct2, 2.5, 'Transition zone, lower target', color='k',fontsize = 9, fontstyle='italic') \n",
    "#    plt.text(dpztApr, 6.5, 'Transition zone, upper target', color='k',fontsize = 9, fontstyle='italic') \n",
    "    plt.text(dpztApr2, 4.9, 'Transition zone, upper target', color='k',fontsize = 9, fontstyle='italic') \n",
    "    # S patens zone: 6 - 12\n",
    "#     axB.axhline(6,color='green')\n",
    "#     axB.axhline(12,color='green')\n",
    "#     plt.text(dpztOct, 6.5, 'S.patens zone, lower target', color='k',fontsize = 9, fontstyle='italic') \n",
    "# #    plt.text(dpztOct, 12.5, 'S. patens zone, upper target', color='k',fontsize = 9, fontstyle='italic') \n",
    "#     plt.text(dpztOct, 10.9, 'S. patens zone, upper target', color='k',fontsize = 9, fontstyle='italic') \n",
    "# add Mottled Duck target    \n",
    "    axB.axhline(9,color='lime')\n",
    "  #  plt.text(dpMDtext1, 7.9, 'Mottled Duck, upper target', color='k',fontsize = 9, fontstyle='italic')\n",
    "    plt.text(dpztJan, 9.5, 'Mottled Duck, upper target', color='k',fontsize = 9, fontstyle='italic')   \n",
    "#\n",
    "    axB.xaxis.grid(True, which=\"major\")\n",
    "#axB.yaxis.grid()\n",
    "    axB.xaxis.set_major_locator(dates.MonthLocator())\n",
    "    axB.xaxis.set_major_formatter(dates.DateFormatter('%b\\n%Y'))\n",
    "    axB.legend(loc='upper left')\n",
    "#Adding text inside a rectangular box by using the keyword 'bbox' \n",
    "    plt.text(dpCelltext, 23, Cell, fontsize = 10)  \n",
    "    plt.tight_layout()     \n",
    "#plt.show()\n",
    "#Save output figure\n",
    "#    OutfileRoot='HandlingVersions_Base-X-3-50day-10kspliced'+Cell\n",
    "#    OutfileRoot='HandlingVersions_Base-X-3-50day-Origs'+Cell\n",
    "    OutfileRoot='Fig9_Base-X3_50day'+Cell\n",
    "    PathOutFile=pathMain+brnchOutAd+OutfileRoot\n",
    "    plt.savefig(PathOutFile)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "#Option 1 - for the defined portion of time series\n",
    "# 6 subplots in a figure\n",
    "# see \"https://www.unidata.ucar.edu/blogs/developer/entry/simple-plotting-in-python-with\"\n",
    "# Titles input previously\n",
    "#\n",
    "Celllist=['Cell 01','Cell 17','Cell 26']\n",
    "#Celllist=['Cell 14']\n",
    "fig, ax1 = plt.subplots(nrows=3,ncols=2,figsize=(16, 16))\n",
    "fig.suptitle('\\n'.join(wrap(MainTitle,45)),fontsize=24,fontweight='bold')\n",
    "fig.text(0.3,0.90,SecondTitle,fontsize=16,fontweight='bold')\n",
    "fig.subplots_adjust(hspace=.4)\n",
    "#fig.subplots_adjust(top=1.25)\n",
    "#\n",
    "for ax1,Cell in zip(ax1.flat,Celllist):\n",
    "# set the appropriate time series\n",
    "#    1st Scenario time series\n",
    "    Y1=TSubA[Cell]\n",
    "#    Y1label=LblRunA\n",
    "    Y2=TSubB[Cell]\n",
    "#    Y2label=LblRunB\n",
    "#    Y2label='G0'+Sc2[0:2]\n",
    "#    ax1.plot_date(Dateplot,Y1,'0.34',linewidth=2,linestyle='-',label=Y1label)\n",
    "    ax1.plot_date(Dateplot,Y1,'0.34',linewidth=2,linestyle='-')\n",
    "# #    2nd Scenario time series\n",
    "#    ax1.plot_date(Dateplot,Y2,'b',linewidth=3,linestyle='-',label=Y2label)\n",
    "    ax1.plot_date(Dateplot,Y2,'b',linewidth=3,linestyle='-')\n",
    "# set particulars of the subplot\n",
    "    ax1.set_xlabel('Date',labelpad=4,fontsize=12)\n",
    "    ax1.set_ylabel('Salinity',labelpad=4,fontsize=12)\n",
    "    ax1.set_ylim(bottom=0,top=25)\n",
    "    ax1.set_title('ICM-'+ Cell)\n",
    "# advanced time axis controls\n",
    "#ax1.xaxis.set_minor_locator(dates.WeekdayLocator(byweekday=(0),\n",
    "#                                                interval=4))\n",
    "#ax1.xaxis.set_minor_formatter(dates.DateFormatter('%d\\n%a'))\n",
    "    ax1.xaxis.grid(True, which=\"major\")\n",
    "#ax1.yaxis.grid()\n",
    "    ax1.xaxis.set_major_locator(dates.MonthLocator())\n",
    "    ax1.xaxis.set_major_formatter(dates.DateFormatter('%b\\n%Y'))\n",
    "    ax1.legend([Y1label,Y2label],loc='upper left', fontsize=10, \\\n",
    "    shadow='true',labelspacing=.7)\n",
    "plt.tight_layout()\n",
    "#plt.show()\n",
    "#Save output figure\n",
    "OutfileRoot='NJ-ICM'+'comp-G001_PIvPIII-'+'array6'\n",
    "#OutfileRoot='NJ-ICM'+'comp-G001_G005-'+'array6'\n",
    "PathOutFile=pathMain+brnchOutAd+OutfileRoot\n",
    "plt.savefig(PathOutFile)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PLOT SET 1 - single large figure with subplots created by a loop"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "#Option 1 - for the defined portion of time series\n",
    "# 6 subplots in a figure\n",
    "# see \"https://www.unidata.ucar.edu/blogs/developer/entry/simple-plotting-in-python-with\"\n",
    "# Titles input previously\n",
    "#\n",
    "#Celllist=['Cell 04','Cell 31','Cell 20','Cell 45','Cell 24','Cell 26']\n",
    "Celllist=['Cell 14']\n",
    "fig, ax1 = plt.subplots(nrows=3,ncols=2,figsize=(16, 16))\n",
    "fig.suptitle('\\n'.join(wrap(MainTitle,45)),fontsize=24,fontweight='bold')\n",
    "fig.text(0.3,0.90,SecondTitle,fontsize=16,fontweight='bold')\n",
    "fig.subplots_adjust(hspace=.4)\n",
    "#fig.subplots_adjust(top=1.25)\n",
    "#\n",
    "for ax1,Cell in zip(ax1.flat,Celllist):\n",
    "# set the appropriate time series\n",
    "#    1st Scenario time series\n",
    "    Y1=TSubA[Cell]\n",
    "#    Y1label=LblRunA\n",
    "    Y2=TSubB[Cell]\n",
    "#    Y2label=LblRunB\n",
    "#    Y2label='G0'+Sc2[0:2]\n",
    "#    ax1.plot_date(Dateplot,Y1,'0.34',linewidth=2,linestyle='-',label=Y1label)\n",
    "    ax1.plot_date(Dateplot,Y1,'0.34',linewidth=2,linestyle='-')\n",
    "# #    2nd Scenario time series\n",
    "#    ax1.plot_date(Dateplot,Y2,'b',linewidth=3,linestyle='-',label=Y2label)\n",
    "    ax1.plot_date(Dateplot,Y2,'b',linewidth=3,linestyle='-')\n",
    "# set particulars of the subplot\n",
    "    ax1.set_xlabel('Date',labelpad=4,fontsize=12)\n",
    "    ax1.set_ylabel('Salinity',labelpad=4,fontsize=12)\n",
    "    ax1.set_ylim(bottom=0,top=25)\n",
    "    ax1.set_title('ICM-'+ Cell)\n",
    "# advanced time axis controls\n",
    "#ax1.xaxis.set_minor_locator(dates.WeekdayLocator(byweekday=(0),\n",
    "#                                                interval=4))\n",
    "#ax1.xaxis.set_minor_formatter(dates.DateFormatter('%d\\n%a'))\n",
    "    ax1.xaxis.grid(True, which=\"major\")\n",
    "#ax1.yaxis.grid()\n",
    "    ax1.xaxis.set_major_locator(dates.MonthLocator())\n",
    "    ax1.xaxis.set_major_formatter(dates.DateFormatter('%b\\n%Y'))\n",
    "    ax1.legend([Y1label,Y2label],loc='upper left', fontsize=10, \\\n",
    "    shadow='true',labelspacing=.7)\n",
    "#\n",
    "#plt.show()\n",
    "#Save output figure\n",
    "OutfileRoot='NJ-ICM'+'comp-G001_PIvPIII-'+'array6'\n",
    "#OutfileRoot='NJ-ICM'+'comp-G001_G005-'+'array6'\n",
    "PathOutFile=pathMain+brnchOutAd+OutfileRoot\n",
    "plt.savefig(PathOutFile)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(PathOutFile)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PLOT SET 2 - multiple single plots, compare 2 scenarios, multiple cells in a loop"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "Celllist=['Cell 04','Cell 34','Cell 16','Cell 38','Cell 25','Cell 45']\n",
    "#Celllist=['6','15']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for Cell in Celllist: \n",
    "#Option A - for the defined portion of time series\n",
    "# Plot the suite of cell results\n",
    "    fig, axB = plt.subplots(1,1,figsize=(12, 3))\n",
    "    axB.plot_date(Dateplot,TSubA[Cell],'r-',linewidth=2,linestyle='--',label=Y1label)\n",
    "# Now add the Grid data\n",
    "    axB.plot_date(Dateplot,TSubB[Cell],'b',linewidth=2,linestyle='-',label=Y2label)\n",
    "# Same as above\n",
    "#    axB.set_xlabel('Date',labelpad=10,fontsize=20)\n",
    "    axB.set_ylabel('Salinity (ppt)',labelpad=10,fontsize=16)\n",
    "    axB.set_ylim(bottom=0,top=25)\n",
    "    axB.set_title(Cell)\n",
    "# advanced time axis controls\n",
    "#axB.xaxis.set_minor_locator(dates.WeekdayLocator(byweekday=(0),\n",
    "#                                                interval=4))\n",
    "#axB.xaxis.set_minor_formatter(dates.DateFormatter('%d\\n%a'))\n",
    "    axB.xaxis.grid(True, which=\"major\")\n",
    "#axB.yaxis.grid()\n",
    "    axB.xaxis.set_major_locator(dates.MonthLocator())\n",
    "    axB.xaxis.set_major_formatter(dates.DateFormatter('%b\\n%Y'))\n",
    "    axB.legend(loc='upper left')\n",
    "    plt.show()\n",
    "#    plt.savefig(pathFileTot)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PARKING LOT"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "FSal='nwf_anwr_icm_salinity'\n",
    "#FSal='NJmirr-nwf_anwr_icm_salinity'\n",
    "FnameDate='_03172021'\n",
    "xclpart='.xlsx'\n",
    "csvpart='.csv'\n",
    "txtpart='.txt'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "CtrlA=open(pathCA,'r')\n",
    "skipA1=6\n",
    "for sk in range(skipA1):\n",
    "    Nuttin=CtrlA.readline()\n",
    "# ---------------- Read the scenarios\n",
    "\n",
    "# Sc1=CtrlA.readline()\n",
    "# Sc2= CtrlA.readline()\n",
    "# Sc1=Sc1.rstrip('\\n')\n",
    "# Sc2=Sc2.rstrip('\\n')\n",
    "# if Trace>0: print('\\n        ******* Control A: Scenarios ********',\n",
    "#                   '\\n _______________________________________________')\n",
    "# if Trace>0: print('Scenarios: Sc1=', Sc1,'Sc2=',Sc2) \n",
    "# cross checks\n",
    "MainTitle=CtrlA.readline()\n",
    "MainTitle=MainTitle.rstrip('\\n')\n",
    "skipA2=2\n",
    "for sk2 in range(skipA2):\n",
    "    Nuttin=CtrlA.readline()\n",
    "#\n",
    "SecondTitle=CtrlA.readline()\n",
    "SecondTitle=SecondTitle.rstrip('\\n')\n",
    "if Trace>0: print('_________________Titles:______________________','\\n Main: ',MainTitle,\\\n",
    "                  '\\n  2nd:', SecondTitle)  \n",
    "skipA2=2\n",
    "for sk in range(skipA2):\n",
    "    Nuttin=CtrlA.readline()    \n",
    "Start=CtrlA.readline()\n",
    "Start=Start.rstrip('\\n')\n",
    "Stop= CtrlA.readline()\n",
    "Stop=Stop.rstrip('\\n')\n",
    "if Trace>0: print(\"        >>>>>> Control A: Times <<<<<<<\",\n",
    "                 \"\\n _______________________________________________\",\n",
    "                 \"\\n  Start time =\", Start,\" Stop time  =\", Stop)                 \n",
    "CtrlA.close"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "ScnOrds=['01','11','12','13','15','16','17']\n",
    "TabDict=['DryBaseline_G001','LesserDrought_G011',\n",
    "'10000acft_50days_G012','10000acft_210days_G013',\n",
    "'G015_0.34cms_Comp14_9ppt','G016_0.34cms_Comp25_15ppt',\n",
    "'G017_0.34cms_9_15ppt']\n",
    "print(TabDict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "Tab1=TabDict[ScnOrds.index(Sc1)]\n",
    "Tab2=TabDict[ScnOrds.index(Sc2)]\n",
    "print(Tab1,\" -- \",Tab2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "## Read scenario data from the Excel file(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "# # Use the date data from Scenario1 input for\n",
    "# # subsequent Scenarios\n",
    "# RunBdata.pop('datePlace')\n",
    "# #\n",
    "# XferDates=RunAdata['date']\n",
    "# #\n",
    "# # inset the date column from Scenario 1\n",
    "# RunBdata.insert(0,'date',XferDates)\n",
    "# #\n",
    "# if Trace>=2: print('\\n ',Tab2,'revised, [Scenario 2] first few rows of data file')\n",
    "# if Trace>=2: print(RunBdata[:4])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
